package haha;

import java.util.Arrays;

public class test01 {

    public static void test1(int[] array) {

        int temp = 0;
        for (int i = 0; i < array.length - 1; i++)
            for (int j = 0; j < array.length - 1; j++) {
                {
                    if (array[j] <array[j + 1]) {
                        temp = array[j];
                        array[j] = array[j + 1];
                        array[j + 1] = temp;
                    //   Arrays.sort(array);

                    }
                }
            }
        for (int i = 0; i < array.length; i++)
            System.out.println(array[i]);
    }

    public static void test2(int[] array) {
        int sum = 0;
        float avg = 0;
        for (int i = 0; i < array.length; i++)
            sum = sum + array[i];
        avg = sum / array.length;
        System.out.println(avg);
    }

    public static void test3(int[] array) {
        int sum = 0;
        for (int i = 1; i < array.length; i = i + 2)
            sum = sum + array[i];
        System.out.println(sum);
    }


    public static void main(String[] args) {

        /* * 需求：给定一个数组{1,3,13,4,9,7,30},
         * 	- 降序排序并显示。
         * 	- 求数组中所有元素的平均值。
         * 	- 求数组中所有下标是奇数的元素的和。*/
        int[] array = {1, 3, 13, 4, 9, 7, 30};
        test1(array);
        test2(array);
        test3(array);
    }
}
